package com.eightbears.beboy.ui.user.activity;

import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.text.Html;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.eightbears.beboy.R;
import com.eightbears.beboy.base.BaseActivity;
import com.eightbears.beboy.base.util.CommonAPI;
import com.eightbears.beboy.base.util.SPUtil;
import com.eightbears.beboy.base.view.GoodProgressView;
import com.eightbears.beboy.base.view.SwipeBackLayout;
import com.eightbears.beboy.entity.UserEntity;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

import static com.eightbears.beboy.R.id.tv_info;

/**
 * 成长页面
 */

public class GrowLevelActivity extends BaseActivity {

    @BindView(R.id.ll_back)
    LinearLayout mLlBack;
    @BindView(R.id.tv_title)
    TextView mTvTitle;
    @BindView(R.id.rl_title_root)
    RelativeLayout mRlTitleRoot;
    @BindView(R.id.tv_right_img_btn)
    TextView mTvRightImgBtn;
    @BindView(R.id.tv_save_address)
    TextView mTvSaveAddress;
    @BindView(R.id.tv_submit)
    TextView mTvSubmit;
    @BindView(R.id.iv_right_icon)
    ImageView mIvRightIcon;
    @BindView(R.id.ll_right)
    LinearLayout mLlRight;
    @BindView(R.id.progressBar)
    ProgressBar mProgressBar;
    @BindView(tv_info)
    TextView mTvInfo;
    @BindView(R.id.iv_info)
    ImageView mIvInfo;
    @BindView(R.id.ll_level)
    LinearLayout mLlLevel;
    @BindView(R.id.gpv_view)
    GoodProgressView gpv_view;
    @BindView(R.id.rl_level)
    RelativeLayout mRlLevel;
    @BindView(R.id.tv_rule)
    TextView mTvRule;
    @BindView(R.id.iv_rule)
    ImageView mIvRule;
    @BindView(R.id.tv_exp)
    TextView mTvExp;
    @BindView(R.id.sw_finish)
    SwipeBackLayout mSw_finish;
    @BindView(R.id.tv_next_exp)
    TextView tv_next_exp;
    @BindView(R.id.tv_award)
    TextView mTvAward;
    @BindView(R.id.tv_info1)
    TextView tv_info1;
    @BindView(R.id.tv_info9)
    TextView tv_info9;
    @BindView(R.id.tv_award_info)
    TextView tv_award_info;
    @BindView(R.id.activity_grow_level)
    RelativeLayout mActivityGrowLevel;
    @BindView(R.id.tv_current_level)
    TextView tv_current_level;
    @BindView(R.id.tv_next_level)
    TextView tv_next_level;

    private UserEntity.User userEntity;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_grow_level);
        ButterKnife.bind(this);
        initView();
        initData();
        initEvent();
    }

    @Override
    protected void initView() {
        userEntity = SPUtil.getUser().getData();

        mTvTitle.setText(getString(R.string.text_my_level));
        gpv_view.setPoints(SPUtil.getUser().getData().getPoints().getPoint());
        gpv_view.setLevel(SPUtil.getUser().getData().getPoints().getLevel());
        gpv_view.invalidate();

        String currentExp = String.format(getString(R.string.text_current_score),
                SPUtil.getUser().getData().getPoints().getPoint() + "");
        mTvInfo.setText(currentExp);
        String nextExp = String.format(getString(R.string.text_next_score),
                SPUtil.getUser().getData().getPoints().getPoint_to_next() + "");
        tv_next_exp.setText(nextExp);
        tv_info1.setText(Html.fromHtml(getString(R.string.text_exp_get_1)));
        tv_info9.setText(Html.fromHtml(getString(R.string.text_exp_get_2)));
        tv_award_info.setText(Html.fromHtml(getString(R.string.text_exp_gift_content)));

        Drawable currentLevel = getResources().getDrawable(CommonAPI.ICON_LEVEL_SEL[userEntity.getPoints().getLevel()-1]);
        currentLevel.setBounds(0, 0, currentLevel.getMinimumWidth(),
                currentLevel.getMinimumHeight());
        tv_current_level.setCompoundDrawables(null, currentLevel, null, null);
        tv_current_level.setText(CommonAPI.TEXT_LEVE[userEntity.getPoints().getLevel()-1]);

        Drawable nextLevel = getResources().getDrawable(
                CommonAPI.ICON_LEVEL[
                        userEntity.getPoints().getLevel() == 5 ? 4 : userEntity.getPoints().getLevel()
                        ]
        );
        nextLevel.setBounds(0, 0, nextLevel.getMinimumWidth(),
                nextLevel.getMinimumHeight());
        tv_next_level.setCompoundDrawables(null, nextLevel, null, null);
        tv_next_level.setText(CommonAPI.TEXT_LEVE[
                userEntity.getPoints().getLevel() == 5 ? 4 : userEntity.getPoints().getLevel()
                ]);
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void initEvent() {
        mSw_finish.setCallBack(new SwipeBackLayout.CallBack() {
            @Override
            public void onFinish() {
                finish();
            }
        });
    }

    @OnClick(R.id.ll_back)
    void back() {
        finish();
    }
}
